/*
 * INSANE - Interactive Structural Analysis Environment
 *
 * Copyright (C) 2003-2004
 * Universidade Federal de Minas Gerais
 * Escola de Engenharia
 * Departamento de Engenharia de Estruturas
 *
 * Author's email :     insane@dees.ufmg.br
 * Author's Website :   http://www.dees.ufmg.br/insane
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-
 * 1307, USA.
 *
 */

package br.ufmg.dees.insane.ui.rich.insaneSolver;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.border.TitledBorder;

import br.ufmg.dees.insane.commons.view.ExtensionFileFilter;
import br.ufmg.dees.insane.persistence.PersistenceAsInsane;
import br.ufmg.dees.insane.persistence.PersistenceAsXML;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.DesktopPostp;

public class SolverInterface extends JFrame{
	
	/**   */
	private static final long serialVersionUID = 1L;
	//Variables declaration - do not modify                     
	private JButton loadFileButton;
	private JButton saveToButton;
	private JButton synhcButton;
	private JButton preProcessorButton;
	private JButton postProcessorButton;
	private JButton solveButton;
	private JButton exitButton;
	private JCheckBox synchronizedCheckBox;
	private JCheckBox binCheckBox;
	private JCheckBox xmlCheckBox;
	private JLabel synchronizedLabel;
	private JPanel loadPanel;
	private JPanel savePanel;
	private JPanel postpPanel;
	private JPanel prepPanel;
	private JPanel synchSolverPanel;
	private JPanel persistencePanel;
	public static JTextArea consoleTextArea;
	private JTextField loadPathTextField;
	private JTextField saveToPathTextField;
	private JSeparator topSeparator;
	// End of variables declaration                   
	
	private JFileChooser fileChooser = new JFileChooser();
	private ExtensionFileFilter filter = new ExtensionFileFilter(new String[]{"xml"}, "XML Files");
	private String path;
	private String name;
	private String savePath;
	private String saveName;
    private String solutionType;
	private SynchronizedSettings synchSettings = new SynchronizedSettings();
	private PersistenceAsXML persistence = new PersistenceAsXML();
	private boolean isPathSet = false;
	
	/** Creates new form InsaneInterface */
	public SolverInterface() {
		initComponents();
	}
	
	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	// <editor-fold defaultstate="collapsed" desc=" Generated Code ">                          
	private void initComponents() {
		
		this.getContentPane().setBackground(Color.white);
		this.setSize(new Dimension(750,330));
		this.setMaximumSize(new Dimension(750,330));
		this.setMinimumSize(new Dimension(750,330));
		this.setPreferredSize(new Dimension(750,330));
		this.setLocation(230,200);
		this.setResizable(false);
		this.setTitle("INSANE SOLVER");
		
		Image ico = Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Insane64.gif"));
		this.setIconImage(ico);
		
		loadPanel = new JPanel();
		savePanel = new JPanel();
		loadFileButton = new JButton();
		saveToButton = new JButton();
		loadPathTextField = new JTextField();
		saveToPathTextField = new JTextField();
		postpPanel = new JPanel();
		prepPanel = new JPanel();
		persistencePanel = new JPanel();
		synchSolverPanel = new JPanel();
		synchronizedCheckBox = new JCheckBox();
		binCheckBox = new JCheckBox();
		xmlCheckBox = new JCheckBox();
		synhcButton = new JButton();
		synchronizedLabel = new JLabel();
		postProcessorButton = new JButton();
		preProcessorButton = new JButton();
		solveButton = new JButton();
		consoleTextArea = new JTextArea();
		exitButton = new JButton();
		topSeparator = new JSeparator();
		
		getContentPane().setLayout(null);
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		
		//INSANE Label
		JLabel logoLabel = new JLabel();
		ImageIcon image = new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/logoInsane2a.gif"));
		logoLabel.setIcon(image);
		getContentPane().add(logoLabel);
		logoLabel.setBounds(8, 5, 750, 50);
		
		getContentPane().add(topSeparator);
		topSeparator.setBackground(new Color(33, 66, 123));
		topSeparator.setBorder(BorderFactory.createLineBorder(new Color(33, 66, 123),2));
		topSeparator.setBounds(0, 60, 745, 225);
		
		//Pre Processor Panel
		prepPanel.setLayout(null);
		prepPanel.setBackground(Color.white);
		prepPanel.setBorder(BorderFactory.createTitledBorder(
				BorderFactory.createLineBorder(new Color(33, 66, 123),2), "Insane Prep", TitledBorder.DEFAULT_JUSTIFICATION, 
				TitledBorder.DEFAULT_POSITION, new Font("Arial", Font.PLAIN, 12),new Color(33, 66, 123)));
		preProcessorButton.setText("Load");
		preProcessorButton.setFont(new Font("Arial", Font.PLAIN,12));
		prepPanel.add(preProcessorButton);
		preProcessorButton.setBounds(150, 20, 70, 23);
		preProcessorButton.addActionListener(
				new ActionListener(){
					public void actionPerformed(ActionEvent event){
						prep();
					}
				});
		
		JLabel jLabel3 = new JLabel();
		jLabel3.setText("Load Pre-Processor:");
		jLabel3.setFont(new Font("Arial", Font.PLAIN,12));
		prepPanel.add(jLabel3);
		jLabel3.setBounds(10, 20, 120, 20);
		
		getContentPane().add(prepPanel);
		prepPanel.setBounds(5, 60, 255, 60);
		
		//Load Panel
		loadPanel.setLayout(null);
		loadPanel.setBackground(Color.white);
		loadPanel.setBorder(BorderFactory.createTitledBorder(
				BorderFactory.createLineBorder(new Color(33, 66, 123),2), "Load", TitledBorder.DEFAULT_JUSTIFICATION,
				TitledBorder.DEFAULT_POSITION, new Font("Arial", Font.PLAIN, 12),new Color(33, 66, 123)));
		
		loadFileButton.setText("Load File");
		loadFileButton.setFont(new Font("Arial", Font.PLAIN, 12));
		loadPanel.add(loadFileButton);
		loadFileButton.setBounds(10, 20, 90, 23);
		
		loadFileButton.addActionListener(
				new ActionListener(){
					public void actionPerformed(ActionEvent event){
						fileChooser = new JFileChooser();
						fileChooser.setFileFilter(filter);
						fileChooser.setFont(new Font("Arial", Font.PLAIN, 12));
						int retVal = fileChooser.showDialog(new JFrame(), "Load File");
						if (retVal == JFileChooser.APPROVE_OPTION) {
							//Getting the file name
							String s = fileChooser.getSelectedFile().getName();
							
							//Getting the file extension
							String ext = new String();
							int i = s.lastIndexOf('.');
							if (i > 0 &&  i < s.length() - 1) {
								ext = s.substring(i+1).toLowerCase();
							}
							//Comparing the extension
							if (!ext.equals("xml")) {
								s = s + ".xml";
								File file = fileChooser.getSelectedFile();
								//Changing the file in case of no good extensions
								fileChooser.setSelectedFile(new File(file.getParent() + File.separator + s));
							}
						}
						if(fileChooser.getSelectedFile()!=null){
							path = fileChooser.getSelectedFile().getAbsolutePath();
							name = fileChooser.getSelectedFile().getName();
							loadPathTextField.setText(path);
							persistence.fillInsaneFromFile(path);
						}
						
					}
				});

		loadPathTextField.setText("");
		loadPanel.add(loadPathTextField);
		loadPathTextField.setBounds(110, 20, 350, 25);
		
		getContentPane().add(loadPanel);
		loadPanel.setBounds(265, 60, 475, 60);
		
		//Persistence panel
		persistencePanel.setLayout(null);
		persistencePanel.setBackground(Color.white);
		persistencePanel.setBorder(BorderFactory.createTitledBorder(
				BorderFactory.createLineBorder(new Color(33, 66, 123),2), "Set Persistence", TitledBorder.DEFAULT_JUSTIFICATION, 
				TitledBorder.DEFAULT_POSITION, new Font("Arial", 0, 12), new Color(33, 66, 123)));
		persistencePanel.setSize(new Dimension(220, 60));
		persistencePanel.setMaximumSize(new Dimension(220, 60));
		persistencePanel.setMinimumSize(new Dimension(220, 60));
		persistencePanel.setPreferredSize(new Dimension(220, 60));
		
		binCheckBox.setText("as Binary Object");
		binCheckBox.setFont(new Font("Arial", 0, 12));
		binCheckBox.setBackground(Color.white);
		binCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
		binCheckBox.setMargin(new Insets(0, 0, 0, 0));
		persistencePanel.add(binCheckBox);
		binCheckBox.setSelected(true);
		binCheckBox.setBounds(5, 25, 120, 20);
		
		xmlCheckBox.setText("XML persistence");
		xmlCheckBox.setFont(new Font("Arial", 0, 12));
		xmlCheckBox.setBackground(Color.WHITE);
		xmlCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
		xmlCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
		persistencePanel.add(xmlCheckBox);
		xmlCheckBox.setBounds(140, 25, 110, 20);
		
		getContentPane().add(persistencePanel);
		persistencePanel.setBounds(5, 120, 255, 60);

		//Save Panel
		savePanel.setLayout(null);
		savePanel.setBackground(Color.white);
		savePanel.setBorder(BorderFactory.createTitledBorder(
				BorderFactory.createLineBorder(new Color(33, 66, 123),2), "Save", TitledBorder.DEFAULT_JUSTIFICATION,
				TitledBorder.DEFAULT_POSITION, new Font("Arial", Font.PLAIN, 12),new Color(33, 66, 123)));
		
		saveToButton.setText("Save To");
		saveToButton.setFont(new Font("Arial", Font.PLAIN,  12));
		savePanel.add(saveToButton);
		saveToButton.setBounds(10, 20, 90, 23);
		saveToButton.addActionListener(
				new ActionListener(){
					public void actionPerformed(ActionEvent event){
						fileChooser = new JFileChooser();
						if(name!=null){
							String aux = name.replace(".xml","");
							fileChooser.setSelectedFile(new File(aux));
						}
						fileChooser.setFont(new Font("Arial", Font.PLAIN,  12));
						int retVal = fileChooser.showDialog(new JFrame(), "Set File");
						if (retVal == JFileChooser.APPROVE_OPTION) {
							//Getting the file name
							String s = fileChooser.getSelectedFile().getName();
							
							//Getting the file extension
							String ext = new String();
							int i = s.lastIndexOf('.');
							if (i > 0 &&  i < s.length() - 1) {
								ext = s.substring(i+1).toLowerCase();
							}
							//Comparing the extension
							if (!ext.equals("xml")) {
								s = s + ".xml";
								File file = fileChooser.getSelectedFile();
								//Changing the file in case of no good extensions
								fileChooser.setSelectedFile(new File(file.getParent() + File.separator + s));
							}
						}
						if(fileChooser.getSelectedFile()!=null){
							savePath = fileChooser.getSelectedFile().getParent();
							saveName = fileChooser.getSelectedFile().getName();
							saveToPathTextField.setText(savePath);
							if(savePath!=""){
								isPathSet = true;
							}
						}
					}
				});
		
		saveToPathTextField.setText("");
		savePanel.add(saveToPathTextField);
		saveToPathTextField.setBounds(110, 20, 350, 25);
		
		getContentPane().add(savePanel);
		savePanel.setBounds(265, 120, 475, 60);
		
//		Pospt processor panel
		postpPanel.setLayout(null);
		postpPanel.setBackground(Color.white);
		postpPanel.setBorder(BorderFactory.createTitledBorder(
				BorderFactory.createLineBorder(new Color(33, 66, 123),2), "Insane Postp", TitledBorder.DEFAULT_JUSTIFICATION, 
				TitledBorder.DEFAULT_POSITION, new Font("Arial", 0, 12), new Color(33, 66, 123)));
		postpPanel.setMinimumSize(new java.awt.Dimension(220, 60));
		postpPanel.setPreferredSize(new java.awt.Dimension(220, 60));
		
		postProcessorButton.setText("Load");
		postProcessorButton.setFont(new Font("Arial", Font.PLAIN,12));
		postpPanel.add(postProcessorButton);
		postProcessorButton.setBounds(150, 20, 70, 23);
		postProcessorButton.addActionListener(
				new ActionListener(){
					public void actionPerformed(ActionEvent event){
						postp();
					}
				});
		
		JLabel jLabel2 = new JLabel();
		jLabel2.setText("Load Post-Processor:");
		jLabel2.setFont(new Font("Arial", Font.PLAIN,12));
		postpPanel.add(jLabel2);
		jLabel2.setBounds(10, 20, 140, 20);
		
		getContentPane().add(postpPanel);
		postpPanel.setBounds(5, 180, 255, 60);
		
		//Synchronized Panel
		synchSolverPanel.setLayout(null);
		synchSolverPanel.setBackground(Color.white);
		synchSolverPanel.setBorder(BorderFactory.createTitledBorder(
				BorderFactory.createLineBorder(new Color(33, 66, 123),2), "Synchronized Settings", TitledBorder.DEFAULT_JUSTIFICATION,
				TitledBorder.DEFAULT_POSITION, new Font("Arial", Font.PLAIN, 12),new Color(33, 66, 123)));
		
		ActionListener synchronizedeList = new SynchronizedCheckBoxListener();         
		synchronizedCheckBox.addActionListener(synchronizedeList);
		
		synchronizedCheckBox.setText("Synchronized On/Off");
		synchronizedCheckBox.setFont(new Font("Arial", Font.PLAIN,12));
		synchronizedCheckBox.setBackground(Color.WHITE);
		synchronizedCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
		synchronizedCheckBox.setMargin(new Insets(0, 0, 0, 0));
		synchSolverPanel.add(synchronizedCheckBox);
		synchronizedCheckBox.setBounds(10, 20, 150, 25);
		
		synhcButton.setText("Settings");
		synhcButton.setEnabled(false);
		synhcButton.setFont(new Font("Arial", Font.PLAIN,12));
		synchSolverPanel.add(synhcButton);
		synhcButton.setBounds(375, 20, 90, 25);
		synhcButton.addActionListener(
				new ActionListener(){
					public void actionPerformed(ActionEvent event){
						synchronizedSettings();
					}
				});
		
		synchronizedLabel.setText("Synchronized Settings:");
		synchronizedLabel.setFont(new Font("Arial", Font.PLAIN,12));
		synchSolverPanel.add(synchronizedLabel);
		synchronizedLabel.setBounds(225, 20, 125, 25);
		
		getContentPane().add(synchSolverPanel);
		synchSolverPanel.setBounds(265, 180, 475, 60);
		
		//Buttons Solve and Close
		solveButton.setText("Solve");
		solveButton.setFont(new Font("Arial", Font.PLAIN,12));
		getContentPane().add(solveButton);
		solveButton.setBounds(272, 250, 100 , 23);
		solveButton.addActionListener(
				new ActionListener(){
					public void actionPerformed(ActionEvent event){
						if(!isPathSet){
							JLabel message = new JLabel();
							message.setFont(new Font("Arial", 0, 12));
							message.setText("You must set a path to save data!");
							JOptionPane.showMessageDialog(null,message, "Error Message", JOptionPane.WARNING_MESSAGE);
						}
						if(!binCheckBox.isSelected()&&!xmlCheckBox.isSelected()){
							JLabel message = new JLabel();
							message.setFont(new Font("Arial", 0, 12));
							message.setText("Set persistence type!");
							JOptionPane.showMessageDialog(null,message, "Error Message", JOptionPane.WARNING_MESSAGE);
						}else{
							solve();
						}
					}
				});
		
		exitButton.setText("Exit");
		exitButton.setFont(new Font("Arial", Font.PLAIN,12));
		getContentPane().add(exitButton);
		exitButton.setBounds(373, 250, 73, 23);
		exitButton.addActionListener(
				new ActionListener(){
					public void actionPerformed(ActionEvent event){
						close(event);
					}
				});
		
		// Botton Label 
		JLabel bottonLabel = new JLabel();
		bottonLabel.setFont(new Font("Arial", 0, 10));
		bottonLabel.setForeground(new Color(33, 66, 123));
		bottonLabel.setText("UFMG - Universidade Federal de Minas Gerais      -"+
				"      DEES - Departamento de Engenharia de Estruturas      -"+"      Version: 2.0.0");
		getContentPane().add(bottonLabel);
		bottonLabel.setBounds(70, 285, 620, 13);
		
		
	}// </editor-fold>                        
	
	public void close(ActionEvent event){
		System.exit(0);
		this.dispose();
	}
	
	public void approvedPerform(){
		
	}
	
	private void synchronizedSettings(){
		new SynchronizedSolverSettingsDialog(this).setVisible(true);
	}
	
	private void postp(){
        LoadPostp loadPostp = new LoadPostp();
        if(isPathSet){
            loadPostp.isPathSet = true;
            loadPostp.saveName = saveName;
            loadPostp.savePath = savePath;
            loadPostp.solutionType = solutionType;
        }
		new Thread(loadPostp).start();
	}
	
	private void prep(){
		new Thread(new LoadPrep()).start();
	}
	
	private void solve(){
		if(!synchronizedCheckBox.isSelected()){
			if(path!=null){
				//PersistenceAsXML p = new PersistenceAsXML();
				PersistenceAsInsane o = new PersistenceAsInsane();
				String aux = saveName.replace(".xml","");
				PersistenceAsXML.path = savePath;
				PersistenceAsXML.fileName = aux;
				PersistenceAsInsane.path = savePath;
				PersistenceAsInsane.fileName = aux;
				PersistenceAsInsane.simpleName = aux;
				if(binCheckBox.isSelected() && xmlCheckBox.isSelected()){
				//	persistence.fillInsaneFromFile(path);
					ShowConsoleWriter console = new ShowConsoleWriter(this,persistence);
					SolverClass solver = new SolverClass(persistence,o);
					solver.setBinObj(true);
					solver.setXML(true);
                     solutionType = persistence.getSolution().getClass().getSimpleName();
					new Thread(console).start();
					new Thread(solver).start();
				}else if(binCheckBox.isSelected() && !xmlCheckBox.isSelected()){
				//	persistence.fillInsaneFromFile(path);
					ShowConsoleWriter console = new ShowConsoleWriter(this,persistence);
					SolverClass solver = new SolverClass(persistence,o);
					solver.setBinObj(true);
					solver.setXML(false);
                     solutionType = persistence.getSolution().getClass().getSimpleName();
					new Thread(console).start();
					new Thread(solver).start();
				}else if(!binCheckBox.isSelected()&& xmlCheckBox.isSelected()){
				//	persistence.fillInsaneFromFile(path);
					ShowConsoleWriter console = new ShowConsoleWriter(this,persistence);
					SolverClass solver = new SolverClass(persistence,o);
					solver.setBinObj(false);
					solver.setXML(true);
                     solutionType = persistence.getSolution().getClass().getSimpleName();
					new Thread(console).start();
					new Thread(solver).start();
				}
			}else{
				JLabel message = new JLabel();
				message.setFont(new Font("Arial", 0, 12));
				message.setText("You must set a file!");
				JOptionPane.showMessageDialog(this,message, "Error Message", JOptionPane.WARNING_MESSAGE);
			}
		}else if(synchronizedCheckBox.isSelected()){
			executeSynchronized();
		}
		
	}
	
	public void executeSynchronized() {
		DesktopPostp frame = new DesktopPostp();
		frame.validate();
		//Centers the window
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		Dimension frameSize = frame.getSize();
		if (frameSize.height > screenSize.height)
			frameSize.height = screenSize.height;
		if (frameSize.width > screenSize.width)
			frameSize.width = screenSize.width;
		frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
		frame.setVisible(true);
		
		PersistenceAsXML p = new PersistenceAsXML();
		PersistenceAsInsane o = new PersistenceAsInsane();
		if(isPathSet){
			String aux = saveName.replace(".xml","");
			PersistenceAsXML.path = savePath;
			PersistenceAsXML.fileName = aux;
			PersistenceAsInsane.path = savePath;
			PersistenceAsInsane.fileName = aux;
			PersistenceAsInsane.simpleName = aux;
		}
		p.fillInsaneFromFile(path);
		
		if(p.getSolution().getClass().getSimpleName().equals("EquilibriumPath")
				||p.getSolution().getClass().getSimpleName().equals("SteadyState")){
            solutionType = p.getSolution().getClass().getSimpleName();
			new Thread(new IConsoleWriter(frame, p,o)).start();
			if(this.synchSettings.isMeshStateOnOff()){
				ShowMeshState meshState = new ShowMeshState(frame, p,o);
				meshState.setSynchSettings(this.synchSettings);
				new Thread(meshState).start();
			}
			if(this.synchSettings.isValueOnOff()){
				ShowMeshValue meshValue = new ShowMeshValue(frame, p,o);
				meshValue.setSynchSettings(this.synchSettings);
				new Thread(meshValue).start();
			}
			if(this.synchSettings.isGraphicOnOff()){
				ShowGraphic graph = new ShowGraphic(frame, p);
				graph.setSynchSettings(this.synchSettings);
				new Thread(graph).start();
			}
			new Thread(new SolverClass(p,o)).start();
		}
		
	}
	
	private class SynchronizedCheckBoxListener implements ActionListener{
		public void actionPerformed(ActionEvent event){
			if(synchronizedCheckBox.isSelected()){
				synhcButton.setEnabled(true);
			}else if(!synchronizedCheckBox.isSelected()){
				synhcButton.setEnabled(false);
				
			}
		}    
	}
	
	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new SolverInterface().setVisible(true);
			}
		});
	}
	
	/**
	 * The method return the synchSettings.
	 * @return Returns The synchSettings.
	 */
	public SynchronizedSettings getSynchSettings() {
		return synchSettings;
	}
	
	/**
	 * The method set the field synchSettings from the parameter synchSettings.
	 * @param synchSettings The synchSettings to set.
	 */
	public void setSynchSettings(SynchronizedSettings synchSettings) {
		this.synchSettings = synchSettings;
	}

	public PersistenceAsXML getPersistence() {
		return persistence;
	}

	public void setPersistence(PersistenceAsXML persistence) {
		this.persistence = persistence;
	}

    public String getSaveName() {
        return saveName;
    }

    public void setSaveName(String saveName) {
        this.saveName = saveName;
    }

    public String getSavePath() {
        return savePath;
    }

    public void setSavePath(String savePath) {
        this.savePath = savePath;
    }

    public String getSolutionType() {
        return solutionType;
    }

    public void setSolutionType(String solutionType) {
        this.solutionType = solutionType;
    }
	
//	******************************************************************************************    
}














